home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / ATOH.ASM < prev    next >
Assembly Source File  |  1992-05-27  |  2KB  |  128 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; ATOH-    Converts the hexadecimal string pointed at by ES:DI to an integer
  10. ;    and returns it in the AX register.
  11. ;
  12. ;    Returns with the carry flag clear if no error, set if overflow.
  13. ;
  14. ; ATOH- preserves di.  ATOH2- Leaves di pointing at first char beyond
  15. ;    hex data.
  16. ;
  17.         public    sl_atoh
  18. sl_atoh        proc    far
  19.         push    di
  20.         call    far ptr sl_atoh2
  21.         pop    di
  22.         ret
  23. sl_atoh        endp
  24. ;
  25.         public    sl_atoh2
  26. sl_atoh2    proc    far
  27.         pushf
  28.         cld
  29.         push    cx
  30.         xor    cx, cx
  31. CnvrtLp:    mov    al, es:[di]
  32.         inc    di
  33.         cmp    al, 'a'
  34.         jb    SkipConvert
  35.         and    al, 5fh
  36. ;
  37. SkipConvert:    xor    al, '0'
  38.         cmp    al, 10
  39.         jb    GotDigit
  40.         add    al, 89h                ;A->0fah.
  41.         cmp    al, 0fah
  42.         jb    Done
  43.         and    al, 0fh                ;0fa..0ff->a..f
  44. GotDigit:    shl    cx, 1                ;Make room for new
  45.         jc    Overflow            ; nibble.
  46.         shl    cx, 1
  47.                 jc    Overflow
  48.         shl    cx, 1
  49.                 jc    Overflow
  50.         shl    cx, 1
  51.         jc    Overflow
  52.         or    cl, al                ;Add in new nibble.
  53.         jmp    CnvrtLp
  54. ;
  55. Overflow:    stc
  56.         jmp    short WasError
  57. ;
  58. Done:        clc
  59. WasError:    mov    ax, cx
  60.         pop    cx
  61.         popf
  62.         ret
  63. sl_atoh2    endp
  64. ;
  65. ;
  66. ; AtoLH - Converts a string of up to 8 hex digits into a long integer
  67. ;      value and returns the result in DX:AX.
  68. ;
  69. ; AtoH- preserves di.  AtoH2- Returns with di pointing at the first char
  70. ;    beyond the string.
  71. ;
  72.         public    sl_atolh
  73. sl_atolh    proc    far
  74.         push    di
  75.         call    far ptr sl_atolh2
  76.         pop    di
  77.         ret
  78. sl_atolh    endp
  79. ;
  80. ;
  81.         public    sl_atolh2
  82. sl_atolh2    proc    far
  83.         pushf
  84.         cld
  85.         push    cx
  86.         xor    cx, cx
  87.                 mov    dx, cx
  88. CnvrtLp2:          mov    al, es:[di]
  89.         inc    di
  90.         and    al, 05fh            ;l.c. -> U.C.
  91.         xor    al, '0'
  92.         cmp    al, 10
  93.         jb    GotDigit2
  94.         add    al, 89h                ;A->10.
  95.         cmp    al, 0fah
  96.         jb    Done2
  97.         and    al, 0fh
  98. GotDigit2:    shl    cx, 1                ;Make room for new
  99.         rcl    dx, 1                           ; nibble.
  100.         jc    Overflow2
  101.         shl    cx, 1
  102.         rcl    dx, 1
  103.         jc    Overflow2
  104.         shl    cx, 1
  105.         rcl    dx, 1
  106.         jc    Overflow2
  107.         shl    cx, 1
  108.         rcl    dx, 1
  109.         jc    Overflow2
  110.         or    cl, al                ;Add in new nibble.
  111.         jmp    CnvrtLp2
  112. ;
  113. Overflow2:    stc
  114.         jmp    short WasError2
  115. ;
  116. Done2:        clc
  117. WasError2:    mov    ax, cx
  118.         pop    cx
  119.         popf
  120.         ret
  121. sl_atolh2    endp
  122. ;
  123. ;
  124. ;
  125. ;
  126. stdlib        ends
  127.         end
  128.